<template>
	<view class="myxuanjia">
		<view class="top_tabars">
			<view v-bind:class="{ 'items_active': change==0, 'items': change!=0 }" @click="changes('0')">
				<text v-bind:class="{ 'line': change==0}">全部</text>
			</view>
			<view v-bind:class="{ 'items_active': change==1, 'items': change!=1 }" @click="changes('1')">
				<text v-bind:class="{ 'line': change==1}">审核中</text>
			 </view>
			<view v-bind:class="{ 'items_active': change==2, 'items': change!=2 }" @click="changes('2')">
				<text v-bind:class="{ 'line': change==2}">审核成功</text>
			</view>
			<view v-bind:class="{ 'items_active': change==3, 'items': change!=3 }" @click="changes('3')">
				<text v-bind:class="{ 'line': change==3}">审核失败</text>
			 </view>
		</view>
		
		<view class="lists">
			<scroll-view scroll-y="true" style="height: 100%;width: 100%;" @scroll="loadMores"  :refresher-threshold="100">
			  <view class="items" v-for="value in lists">
				  <view class="centers" @click="infos(value)">
					  <view class="goods_images" v-if="value.images!=null">
						  <image :src="value.images[0]" mode="" ></image>
					  </view>
					  <view class="goods_images" v-if="value.images==null">
						  
					  </view>
					  <view class="goods_info">
						   <view class="title">{{value.name}}</view>
						   <view class="content">{{value.type_name}}</view>
						   <view class="price">预计采购数量:{{value.estimate_num}}件</view>
						   <view class="num">预算:{{value.estimate}}元</view>
					  </view>
					  <view class="goods_status" v-if="value.status==1">审核中</view>
					  <view class="goods_status" v-if="value.status==2">审核成功</view>
					  <view class="goods_status" v-if="value.status==3">审核失败</view>
				  </view>
				  <view class="goods_btn">
					  <view class="btn-oks" v-if="value.status==1" @click="tabsss(value)">未通过</view>
					  <view class="btn-ok" v-if="value.status==1" @click="tongguo(value)">通过</view>
					  <view class="fonts" v-if="value.status==3">{{value.reason}}</view>
				  </view>
			   </view>
			</scroll-view>
		</view>
		
		<view class="black_moban" v-show="showsss"></view>
		<view class="wuliu_top" v-show="showsss">
			 <view class="titles">
				<textarea v-model="reason" placeholder="请输入未通过原因" class="index-title"></textarea>
			 </view>
			<view class="center">
				<view class="left" @click="closess()">取消</view>
				<view class="right" @click="submitsss()">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		ajax
	} from '../../ajax.js';
	export default {
		data() {
		return {
			firstNum:1,
			num:20,
			type:0,
			lists:'',
			change:0,
			shows:false,
			showss:false,
			showsss:false,
			value:'',
			values:'',
			valuess:'',
			reason:''
		  }
		},
		onLoad() {
			this.getlist()
			
		},
		onPullDownRefresh() {
			this.loadMores()
		},
		onReachBottom(e) {
			this.loadMores();
		},
		methods:{
			changes(value){
				let that=this
				that.change=value
				that.type=value
				that.getlist()
			},
			loadMores(){
				let that = this
				let status = that.type
				let num = that.num
				let token = uni.getStorageSync('token')
				that.firstNum=that.firstNum+1
				if(that.firstNum>that.last_page){
					uni.showToast({
						title: "没有更多数据",
						icon:'none'
					})
					return
				}
				//that.list=[]
				ajax({
					url: 'goods/getGoodsBargain',
					data: {
						token: token,
						firstNum: that.firstNum,
						num: num,
						status: status
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data.data)
						//res.data.data.data[0].status_text='已发货'
						   /**
						   res.data.data.data.slice(0).forEach(e => {
							  that.list.push(e);
							});**/
							for(var i=0;i<res.data.data.data.length;i++){
								if(res.data.data.data[i].good!=null){
									//that.lists[i].status=1
									res.data.data.data[i].name=res.data.data.data[i].good.name
									res.data.data.data[i].good_id=res.data.data.data[i].good.good_id
									res.data.data.data[i].images=res.data.data.data[i].good.images
									res.data.data.data[i].type_id=res.data.data.data[i].good.type_id
									res.data.data.data[i].type_name=res.data.data.data[i].good.type_name
								    that.lists.push(res.data.data.data[i]);
								}
							}
						that.last_page=res.data.data.last_page
						
					},
					error: function() {
							
					}
				});
			},
			infos(value){
				uni.navigateTo({
					url:'/pages/mine/myxuanjia_info?id='+value.spec_id
				})
			},
			tabsss(value){
			  this.valuess=value
			  this.showsss=true
			},
			tongguo(value){
				let that =this
				ajax({
					url: 'goods/editGoodStatus',
					data: {
						token:uni.getStorageSync('token'),
						good_id: value.good_id,
						spec_id:value.spec_id,
						status:2,
						reason:''
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data)
						if(res.data.code==1){
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
							this.showsss=false
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						}
				},
				error: function() {
						
				  }
				});	
			},
			submitsss(){
				let that =this
				let valuess=that.valuess
				if(that.reason==''){
					uni.showToast({
						title:'请输入未通过原因',
						duration: 1500,
						icon: 'none'
					});
				  return
				}
				ajax({
					url: 'goods/editGoodStatus',
					data: {
						token:uni.getStorageSync('token'),
						good_id: valuess.good_id,
						spec_id:valuess.spec_id,
						status:3,
						reason:that.reason
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data)
						if(res.data.code==1){
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
							this.showsss=false
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						}
				},
				error: function() {
						
				}
				});
			},
			loadMores(){
				
			},
			closess(){
				this.showsss=false
			},
			getlist(){
				let that = this
				let status = that.type
				let firstNum = that.firstNum
				let num = that.num
				let token = uni.getStorageSync('token')
				that.list=[]
				ajax({
					url: 'goods/getGoodsBargain',
					data: {
						token: token,
						firstNum: firstNum,
						num: num,
						status: status
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						//console.log(res.data.data.data)
						//res.data.data.data[0].status_text='已发货'
						that.lists = res.data.data.data
						console.log( that.lists,"0000")
						for(var i=0;i<res.data.data.data.length;i++){
							if(res.data.data.data[i].good!=null){
								//that.lists[i].status=1
								that.lists[i].name=res.data.data.data[i].good.name
								that.lists[i].good_id=res.data.data.data[i].good.good_id
								that.lists[i].images=res.data.data.data[i].good.images
								that.lists[i].type_id=res.data.data.data[i].good.type_id
								that.lists[i].type_name=res.data.data.data[i].good.type_name
							}
						}
						//that.lists = res.data.data.data
						//this.last_page=res.data.data.last_page
						
					},
					error: function() {
							
					}
				});
			}
		}
	}
	
</script>

<style lang="scss">
	page{
		background: #F7F7F7;
	}
	.black_moban{
		width: 750rpx;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		position: absolute;
		top: 0;
		z-index: 100;
	}
	.wuliu_top{
		width: 620rpx;
		height: 207rpx;
		z-index: 1000;
		background-color: #FFFFFF;
		position: absolute;
		top: 401rpx;
		left: 65rpx;
		border-radius: 20rpx;
		.index-title{
			width: 96%;
			padding: 2%;
			height: 160rpx;
			overflow: hidden;
		 }
		.center{
			width: 100%;
			overflow: hidden;
			margin: 0rpx auto;
			
			.left{
				width: 50%;
				line-height: 90rpx;
				height: 90rpx;
				text-align: center;
				color: #333;
				background: #F7F7F7;
				float: left;
				border-bottom-left-radius:20rpx
			}
			.right{
				width: 50%;
				line-height: 90rpx;
				height: 90rpx;
				text-align: center;
				color: #FFFFFF;
				background: #FF7427;
				float: left;
				border-bottom-right-radius:20rpx
			}
		}
		.title{
			font-size: 32rpx;
			padding: 48rpx 0rpx 48rpx 0rpx;
			text-align: center;
		}
	}
	.myxuanjia{
		
		
		.lists{
			width: 100%;
			margin: 58rpx auto auto auto;
			padding: 0rpx 0rpx;
			.items{
				width: 90%;
				padding: 2.5%;
				overflow: hidden;
				font-size: 28rpx;
				margin: 20rpx auto;
				background-color: #FFFFFF;
				border-radius: 12rpx;
				.centers{
					width: 100%;
					overflow: hidden;
					margin: 0rpx auto;
					font-size: 28rpx;
					.goods_images{
						float: left;
						width: 28%;
						image{
							width: 158rpx;
							height: 158rpx;
						}
					}
					.goods_info{
						width: 40%;
						float: left;
						.title{
							color: #333333;
							font-size: 26rpx;
							
						}
						.content{
							color: #555555;
							font-size: 20rpx;
						}
						.price{
							color: #555555;
							font-size: 24rpx;
						}
						.num{
							color: #555555;
							font-size: 24rpx;
						}
						
					}
					.goods_status{
						width: 22%;
						float: left;
						color: #FF7427;
						font-size: 28rpx;
						text-align: right;
					}
				}
				.goods_btn{
					width: 100%;
					overflow: hidden;
					border-top: 2rpx solid #f7f7f7;
					.btn-ok{
						width: 108rpx;
						float: right;
						height: 48rpx;
						line-height: 48rpx;
						margin-left: 14rpx;
						border-radius: 24rpx;
						color: #FFFFFF;
						background: #FF7427;
						text-align: center;
					}
					.fonts{
						text-align: right;
					}
					.btn-oks{
						width: 108rpx;
						height: 48rpx;
						float: right;
						line-height: 48rpx;
						margin-left: 14rpx;
						border-radius: 24rpx;
						color: #FFFFFF;
						background:#FF7427;
						text-align: center;
					}
				}
			}
		}
		
		.top_tabars{
			width: 100%;
			height: 68rpx;
			position: fixed;
			top: 68rpx;
			z-index: 100;
			left: 0rpx;
			background: #F7F7F7;
			color: #333333;
			overflow: hidden;
			background: #F7F7F7;
			.items{
				float: left;
				width: 25%;
				overflow: hidden;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				font-size: 28rpx;
				color: #333333;
			}
			.line{
				width: 128rpx;
				line-height: 46rpx;
				height: 46rpx;
				display: inline-block;
				border-bottom: 2rpx solid #FF7427;
			}
			.items_active{
				float: left;
				width: 25%;
				overflow: hidden;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				font-size: 28rpx;
				color: #FF7427;
				
			}
		}
	}
	
</style>
